<template>
  <div class="knowledgeTypeEdit">
    <!-- 知识类型新增修改弹窗 -->
    <el-dialog
      title="审核"
      :visible.sync="dialogVisible"
      :show-close="true"
      :close-on-click-modal="false"
      :before-close="closeDailog"
      center
    >
      <FormContainer :column="1">
        <el-form ref="form" :model="formData" :rules="formRules" label-width="40px">
          <el-form-item prop="auditRemarks" label="备注">
            <el-input v-model="formData.auditRemarks" type="textarea" :autosize="{minRows: 5}" clearable />
          </el-form-item>
          <el-form-item>
            <Button type="primary" :loading="loading" @click="examineClick(3)">审核不通过</Button>
            <Button type="primary" :loading="loading" @click="examineClick(2)">审核通过</Button>
          </el-form-item>
        </el-form>
      </FormContainer>
    </el-dialog>
  </div>
</template>
<script>
import FormContainer from '@/components/FormContainer'
import Button from '@/components/Button'
import { auditKonwledgeType } from '@/api/knowledgeType'
import { parseTime } from '@/utils'
export default {
  name: 'EnowledgeTypeEdit',
  components: {
    FormContainer,
    Button
  },
  props: {
  },
  data() {
    return {
      dialogVisible: false,
      loading: false,
      formData: {
        auditRemarks: ''
      },
      curData: {
        id: ''
      },
      formRules: {
        auditRemarks: {
          required: true, message: '请输入审核备注', trigger: 'blur'
        }
      }
    }
  },
  methods: {
    // 打开弹窗
    openDailog(data) {
      this.curData = data
      this.dialogVisible = true
    },
    closeDailog() {
      this.dialogVisible = false
    },
    // 审核
    examineClick(state) {
      const id = this.curData.id
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.loading = true
          if (id) {
            auditKonwledgeType({ id, state, auditRemarks: this.formData.auditRemarks, auditTime: parseTime(new Date()) })
              .then(res => {
                this.loading = false
                if (res.success === 1) {
                  this.closeDailog()
                  this.$emit('requestSinga', true)
                  this.$message({
                    message: '审核完成!',
                    type: 'success'
                  })
                }
              }).catch(er => {
                this.loading = false
              })
          }
        }
      })
    }
  }
}
</script>
<style lang='scss' scoped>
.buttons-center{
  display: flex;
  margin-bottom: 20px;
  i{
    flex-grow: 1;
  }
}
</style>
